#include "Model.h"
#include <vector>
#include <string>
#include <iostream>

Model::Model() {
	textBooks.resize(2); 
}


std::string Model::getText(size_t pos) {
	return currentTextSource->getLine(pos);
}

void Model::addText(std::string txt) {
	currentTextSource->addLine(txt);
}

size_t Model::getBookSize() {
	return currentTextSource->getBookSize();
}

void Model::switchSourceWOCount(int src) {

	switch (src) {
		case 0 : currentTextSource = &textBooks.at(0);
			 break;
		case 1 : currentTextSource = &textBooks.at(1);
			 break;
	}

}

void Model::switchSource(int src) {
	int temp = 0;
	int points = 0;
	switch (src) {
		case 0 : temp = currentTextSource->getLinesRed();
			 points = currentTextSource->getPointIndex(temp);
			 currentTextSource = &textBooks.at(0);
			 currentTextSource->setLinesRed(currentTextSource->getLineByPointIndex(points));			 	
			 break;
		case 1 : temp = currentTextSource->getLinesRed();
			 points = currentTextSource->getPointIndex(temp);
			 currentTextSource = &textBooks.at(1);
			 currentTextSource->setLinesRed(currentTextSource->getLineByPointIndex(points));		
			 break;

	}
}

void Model::switchSource() {
	source = source == 1 ? 0 : 1;
	switchSource(source);
}

void Model::addPointIndex(int i) {
	currentTextSource -> addPointIndex(i);
}

int Model::getLinesRed() {
	return currentTextSource->getLinesRed();
}

void Model::setLinesRed(int i) {
	currentTextSource->setLinesRed(i);
}

Model::~Model() {
	// по ходу дела, ничего
}
